///////////////////////////////////////////////////////////
///////////////// Have an itch? Scratch it! ///////////////
///////////////////////// SCRATCH /////////////////////////
/////////////////////  A MUD  Server   ////////////////////
///////////////////// By: Jared Devall ////////////////////
/////////////////////      Thanks:     ////////////////////
/////////////////////  DIKU/Merc/ROM   ////////////////////
///////////////////// Aetas/Deus Gang  ////////////////////
/////////////////////       Beej       ////////////////////
///////////////////////////////////////////////////////////

#include "definitions.h"
#include <list>
#include "commands.h"
#include "commandTable.h"
#include "stringutil.h"
#include "vEditHandler.h"

// Command definitions for medit commands
// (Keep in alphabetical order... it's MUCH easier)
mCmdAc::mCmdAc() {
	SetName( "ac" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdAc::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: ac <number>\n\r" );
		return false;
	}

	c->getMob()->setAc( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdAcbash::mCmdAcbash() {
	SetName( "acbash" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdAcbash::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: acbash <number>\n\r" );
		return false;
	}

	c->getMob()->setAcbash( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdAcslash::mCmdAcslash() {
	SetName( "acslash" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdAcslash::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: acslash <number>\n\r" );
		return false;
	}

	c->getMob()->setAcslash( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdAcpierce::mCmdAcpierce() {
	SetName( "acpierce" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdAcpierce::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: ac <number>\n\r" );
		return false;
	}

	c->getMob()->setAcpierce( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdAcexotic::mCmdAcexotic() {
	SetName( "acexotic" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdAcexotic::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: acexotic <number>\n\r" );
		return false;
	}

	c->getMob()->setAcexotic( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdCha::mCmdCha() {
	SetName( "cha" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdCha::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: cha <number>\n\r" );
		return false;
	}

	c->getMob()->setMcha( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdClass::mCmdClass() {
	SetName( "class" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdClass::Execute( Character* c, const string& args ) {
	std::string tmp = args;

	if ( args.empty() ) {
		c->Send( "syntax: class\n\r" );
		return false;
	}

	c->getMob()->setClass( Creature::intClass( tmp ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdCommands::mCmdCommands() {
	SetName( "commands" );
	SetLevel( 1 );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdCommands::Execute( Character* c, const string& args ) {
	std::string buf;
	std::string temp;
	list< Command* >::iterator it;
	int f = 0;

	if ( c->getLevel() >= HEAD ) {
		buf << "\n\r\t{chead (level " << HEAD << ") commands:{x\n\r";
		for ( it = mCommandTable::Instance()._commands.begin(); it != mCommandTable::Instance()._commands.end(); ++it ) {
			if ( (*it)->_level == HEAD ) {
				if ( !(*it)->_enabled )
					buf << "{w";
				if ( f == 0 ) {
					buf << "  " << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				} else {
					buf << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				}
				if ( !(*it)->_enabled )
					buf << "{x";
			    f++;
			    if ( f == 5 ) {
					buf << "\n\r";
					f = 0;
				}
			}
		}
	}
	if ( f != 0 && f != 5 )
		buf << "\n\r";
	f = 0;
	if ( c->getLevel() >= GOD ) {
		buf << "\n\r\t{cgod (level " << GOD << ") commands:{x\n\r";
		for ( it = mCommandTable::Instance()._commands.begin(); it != mCommandTable::Instance()._commands.end(); ++it ) {
			if ( (*it)->_level == GOD ) {
				if ( !(*it)->_enabled )
					buf << "{w";
				if ( f == 0 ) {
					buf << "  " << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				} else {
					buf << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				}
				if ( !(*it)->_enabled )
					buf << "{x";
			    f++;
			    if ( f == 5 ) {
					buf << "\n\r";
					f = 0;
				}
			}
		}
	}
	if ( f != 0 && f != 5 )
		buf << "\n\r";
	f = 0;
	if ( c->getLevel() >= BUILDER ) {
		buf << "\n\r\t{cbuilder (level " << BUILDER << ") commands:{x\n\r";
		for ( it = mCommandTable::Instance()._commands.begin(); it != mCommandTable::Instance()._commands.end(); ++it ) {
			if ( (*it)->_level == BUILDER ) {
				if ( !(*it)->_enabled )
					buf << "{w";
				if ( f == 0 ) {
					buf << "  " << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				} else {
					buf << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				}
				if ( !(*it)->_enabled )
					buf << "{x";
			    f++;
			    if ( f == 5 ) {
					buf << "\n\r";
					f = 0;
				}
			}
		}
	}
	if ( f != 0 && f != 5 )
		buf << "\n\r";
	f = 0;
	buf << "\n\r\t{c-- Commands --{x \n\r";
	for ( it = mCommandTable::Instance()._commands.begin(); it != mCommandTable::Instance()._commands.end(); ++it ) {
		if ( (*it)->_level == 1 ) {
				if ( !(*it)->_enabled )
					buf << "{w";
				if ( f == 0 ) {
					buf << "  " << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				} else {
					buf << (*it)->_name.c_str() << spaces( 12, (*it)->_name.c_str(), temp );
				}
				if ( !(*it)->_enabled )
					buf << "{x";
		    f++;
		    if ( f == 5 ) {
				buf << "\n\r";
				f = 0;
			}
		}
	}

	if ( f != 0 && f != 5 )
		buf << "\n\r";

	c->Send( buf );

	return true;
}

mCmdCon::mCmdCon() {
	SetName( "con" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdCon::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: con <number>\n\r" );
		return false;
	}

	c->getMob()->setMcon( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdDr::mCmdDr() {
	SetName( "dr" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdDr::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: dr <number>\n\r" );
		return false;
	}

	c->getMob()->setDr( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdDescription::mCmdDescription() {
	SetName( "description" );
	SetLevel( BUILDER );
	SetEnabled( true );	
	SetOmniset( false );
}

bool mCmdDescription::Execute( Character* c, const string& args ) {

	c->setVEdit( true );
	vEditList::Instance().act( c, args );

	return true;
}

mCmdDex::mCmdDex() {
	SetName( "dex" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdDex::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: dex <number>\n\r" );
		return false;
	}

	c->getMob()->setMdex( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdExit::mCmdExit() {
	SetName( "exit" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdExit::Execute( Character* c, const string& args ) {

	c->SetStatus( CONNECTED );
	c->setMob( NULL );
	c->Send( "You've been set to regular command mode.\n\r" );

	return true;
}

mCmdGender::mCmdGender() {
	SetName( "gender" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdGender::Execute( Character* c, const string& args ) {
	std::string tmp = args;

	if ( args.empty() ) {
		c->Send( "syntax: gender <male|female|neutral>\n\r" );
		return false;
	}

	c->getMob()->setGender( Creature::intGender( tmp ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdHp::mCmdHp() {
	SetName( "hp" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdHp::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: hp <number>\n\r" );
		return false;
	}

	c->getMob()->setMhp( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdHr::mCmdHr() {
	SetName( "hr" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdHr::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: hr <number>\n\r" );
		return false;
	}

	c->getMob()->setHr( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdInt::mCmdInt() {
	SetName( "int" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdInt::Execute( Character* c, const string& args ) {
	std::string buf;

	if ( args.empty() ) {
		c->Send( "syntax: int <number>\n\r" );
		return false;
	}

	c->getMob()->setMintel( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdLevel::mCmdLevel() {
	SetName( "level" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdLevel::Execute( Character* c, const string& args ) {
	std::string buf;

	if ( args.empty() ) {
		c->Send( "syntax: level <number>\n\r" );
		return false;
	}

	c->getMob()->setLevel( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdLong::mCmdLong() {
	SetName( "long" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdLong::Execute( Character* c, const string& args ) {
	std::string buf;
	std::string tmp = args;

	if ( args.empty() ) {
		c->Send( "syntax: long <description>\n\r" );
		return false;
	}

	c->getMob()->setLong( tmp );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdMana::mCmdMana() {
	SetName( "mana" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdMana::Execute( Character* c, const string& args ) {
	std::string buf;

	if ( args.empty() ) {
		c->Send( "syntax: mana <number>\n\r" );
		return false;
	}

	c->getMob()->setMmana( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdMove::mCmdMove() {
	SetName( "move" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdMove::Execute( Character* c, const string& args ) {
	std::string buf;

	if ( args.empty() ) {
		c->Send( "syntax: move <number>\n\r" );
		return false;
	}

	c->getMob()->setMmove( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdName::mCmdName() {
	SetName( "name" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdName::Execute( Character* c, const string& args ) {
	std::string tmp = args;

	if ( args.empty() ) {
		c->Send( "syntax: name <string>\n\r" );
		return false;
	}

	c->getMob()->setName( tmp );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdRace::mCmdRace() {
	SetName( "race" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdRace::Execute( Character* c, const string& args ) {
	std::string tmp = args;

	if ( args.empty() ) {
		c->Send( "syntax: race <string>\n\r" );
		return false;
	}

	c->getMob()->setRace( Creature::intRace( tmp ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdSaves::mCmdSaves() {
	SetName( "saves" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdSaves::Execute( Character* c, const string& args ) {
	std::string tmp = args;

	if ( args.empty() ) {
		c->Send( "syntax: saves <number>\n\r" );
		return false;
	}

	c->getMob()->setSaves( Creature::intRace( tmp ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdShort::mCmdShort() {
	SetName( "short" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdShort::Execute( Character* c, const string& args ) {
	std::string tmp = args;

	if ( args.empty() ) {
		c->Send( "syntax: short <string>\n\r" );
		return false;
	}

	c->getMob()->setShort( tmp );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdStr::mCmdStr() {
	SetName( "str" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdStr::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: str <number>\n\r" );
		return false;
	}

	c->getMob()->setMstr( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdView::mCmdView() {
	SetName( "view" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdView::Execute( Character* c, const string& args ) {
	std::string tmp;
	std::string buf;

	buf << "{Cac:{x        " << format( 25, c->getMob()->getAc(), tmp );
	buf << "{Cac bash:{x   " << format( 25, c->getMob()->getAcbash(), tmp ) << "\n\r";
	buf << "{Cac slash:{x  " << format( 25, c->getMob()->getAcslash(), tmp );
	buf << "{Cac pierce:{x " << format( 25, c->getMob()->getAcpierce(), tmp ) << "\n\r";
	buf << "{Cac exotic:{x " << format( 25, c->getMob()->getAcexotic(), tmp );
	buf << "{Ccha:{x       " << format( 25, c->getMob()->getMcha(), tmp ) << "\n\r";
	buf << "{Cclass:{x     " << format( 25, c->getMob()->stringClass(), tmp );
	buf << "{Ccon:{x       " << format( 25, c->getMob()->getMcon(), tmp ) << "\n\r";
	buf << "{Cdr:{x        " << format( 25, c->getMob()->getDr(), tmp );
	buf << "{Cdex:{x       " << format( 25, c->getMob()->getMdex(), tmp ) << "\n\r";
	buf << "{Cgender:{x    " << format( 25, c->getMob()->stringGender(), tmp );
	buf << "{Chp:{x        " << format( 25, c->getMob()->getMhp(), tmp ) << "\n\r";
	buf << "{Chr:{x        " << format( 25, c->getMob()->getHr(), tmp );
	buf << "{Cint:{x       " << format( 25, c->getMob()->getMintel(), tmp ) << "\n\r";
	buf << "{Clevel:{x     " << format( 25, c->getMob()->getLevel(), tmp );
	buf << "{Clong:{x      " << format( 25, c->getMob()->getLong(), tmp ) << "\n\r";
	buf << "{Cmana:{x      " << format( 25, c->getMob()->getMmana(), tmp );
	buf << "{Cmove:{x      " << format( 25, c->getMob()->getMmove(), tmp ) << "\n\r";
	buf << "{Cname:{x      " << format( 25, c->getMob()->getName(), tmp );
	buf << "{Crace:{x      " << format( 25, c->getMob()->stringRace(), tmp ) << "\n\r";
	buf << "{Csaves:{x     " << format( 25, c->getMob()->getSaves(), tmp );
	buf << "{Cshort:{x     " << format( 25, c->getMob()->getShort(), tmp ) << "\n\r";
	buf << "{Cstr:{x       " << format( 25, c->getMob()->getMstr(), tmp );
	buf << "{Cvnum:{x      " << format( 25, c->getMob()->getVnum(), tmp ) << "\n\r";
	buf << "{Cwimpy:{x     " << format( 25, c->getMob()->getWimpy(), tmp );
	buf << "{Cwis:{x       " << format( 25, c->getMob()->getMwis(), tmp ) << "\n\r";
	buf << "{CDescription:{x\n\r" << c->getMob()->getDesc() << "\n\r";

	c->Send( buf );

	return true;
}

mCmdWimpy::mCmdWimpy() {
	SetName( "wimpy" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdWimpy::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: wimpy <number>\n\r" );
		return false;
	}

	c->getMob()->setWimpy( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}

mCmdWis::mCmdWis() {
	SetName( "wis" );
	SetLevel( BUILDER );
	SetEnabled( true );
	SetOmniset( false );
}

bool mCmdWis::Execute( Character* c, const string& args ) {

	if ( args.empty() ) {
		c->Send( "syntax: wis <number>\n\r" );
		return false;
	}

	c->getMob()->setMwis( atoi( args.c_str() ) );

	mCmdView cmdView;
	cmdView.Execute( c, "null" );

	return true;
}
